<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <head>
        <meta charset="UTF-8">
        <title>模板管理</title>
        <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}">
        <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}">
        <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/color.css}">
        <link rel="stylesheet" type="text/css" th:href="@{/easyui/demo/demo.css}">
        <script type="text/javascript" th:src="@{/easyui/jquery.min.js}"></script>
        <script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>
        <script type="text/javascript" th:src="@{/easyui/locale/easyui-lang-zh_CN.js}"></script>
    </head>
</head>
<body style="padding: 0px">
<table id="dg" title="模板列表" class="easyui-datagrid" style="width:100%;height:800px"
       toolbar="#toolbar"
       pagination="true"
       striped="true"
       url="getTemplates"
       rownumbers="true"
       fitColumns="true"
       singleSelect="true"
       fit="true"
       loadMsg="正在查询...">
    <thead>
    <tr>
        <th field="id" width="5%" >模板号</th>
        <th field="path" width="10%" data-options="editor:'text'">模板存储路径</th>
        <th field="createTime" width="10%" data-options="editor:'text'">模板上传时间</th>
        <th field="isUsing" width="5%" data-options="editor:'text'">是否正在使用</th>
        <th field="versionNum" width="10%" data-options="editor:'text'">版本号</th>
        <th field="updateTime" width="10%" data-options="editor:'text'">更新时间</th>
        <th field="note" width="10%" data-options="editor:'text'">说明</th>
        <th field="ossUrl" width="20%" data-options="editor:'text'">下载链接</th>
        <th field="jpgOssUrl" width="20%" data-options="editor:'text'">模板图片下载链接</th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="#button" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="uploadidalogonline();">上传模板文件</a>
<!--    <a  href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="uploadimage(1)">上传模板图片</a>-->
    <a  href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="openPDF()">预览模板</a>
</div>

<div id="uploadonlineinfo" class="easyui-window" style="width:380px;padding:10px 40px" closed="true">
    <form id="fam" method="post" enctype="multipart/form-data">
        <table border="0" style="margin-top:4px;" width="100%" align="center">
            <tr>
                <td>
                    <input class="easyui-filebox" name="upload" data-options="buttonText:'选择文件',prompt:'文件上传'" style="width:100%"></input>
                </td>
            </tr>
        </table>
    </form>

    <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="uploadonline(0,'#fam');" style="width:80px">上传</a>
    </div>
</div>

<div id="uploadimage" class="easyui-window" style="width:380px;padding:10px 40px" closed="true">
    <form id="image" method="post" enctype="multipart/form-data">
        <table border="0" style="margin-top:4px;" width="100%" align="center">
            <tr>
                <td>
                    <input class="easyui-filebox" name="upload" data-options="buttonText:'选择文件',prompt:'文件上传'" style="width:100%"></input>
                </td>
            </tr>
        </table>
    </form>

    <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="uploadonline(1,'#image');" style="width:80px">上传</a>
    </div>
</div>


</body>
<script type="text/javascript">

    function uploadidalogonline() {
        $('#uploadonlineinfo').window('open').dialog('setTitle','模板文件上传');
    }

    function uploadonline(model,id) {
        if(model==1)
        {
            var add="../../../hetong/web/uploadContractTemplateImage";
        }
        else
        {
            var add="../../../hetong/web/uploadContractTemplate";
        }
        $(id).form('submit',{
            url: add,
            onSubmit: function(){

            },
            success: function(result){
                var result = eval('('+result+')');
                if (result.status==200){
                    $('#uploadonlineinfo').window('close');
                    $('#dg2').datagrid('reload');
                    $.messager.show({
                        title: 'Success',
                        msg: '上传成功'
                    });
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result.message
                    });
                }
            }
        });
    }



    function uploadimage() {
        $('#uploadimage').window('open').dialog('setTitle','模板图片上传');
    }

    //查看模板
    function openPDF()
    {
        var row = $('#dg').datagrid('getSelected');
        var templateId=row.id;
        if (row){
            var url="../../../hetong/download/watchTemplate?templateId="+templateId;
            window.open(url);
        }
    }

</script>
</html>